package com.itheima.domain;

import java.util.Scanner;

/*
* 评委打分
* 用方法来弄评委打分
* */
public class Mark {

    public static void main(String[] args) {
        //创建键盘录入对象
        Scanner sc= new Scanner(System.in);
        System.out.println("请输入打分人数");
        int numders = sc.nextInt();
        //调用打分方法
        int[] arr = daFen(numders);
        System.out.println("max:"+getMax(arr));
        System.out.println("min:"+getMin(arr));
        System.out.println("sum:"+getSum(arr));
        System.out.println("avg"+(getSum(arr)-getMax(arr)-getMin(arr))/(arr.length-2));
    }
    //求最大值
    public static int getMax (int []arr){
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        return max;
    }
    //求最小值
    public  static int getMin(int[]arr){
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (min < arr[i]) {
                min = arr[i];
            }
        }
        return min;
    }
    //求和
    public static int getSum(int []arr){
        int sum=0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        return sum;
    }

    /**
     * 返回值类型为int[]
     * 参数列表为: int numbers(评委人数自定义 和键盘录入)
     * @param numders
     * @return
     */
    public  static int[] daFen(int numders){
        //动态出示或数组,长度为传递进来的人数
        int[]arr= new int[numders];
        Scanner sc= new Scanner(System.in);
        //遍历元素,给元素赋值
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第"+(i+1)+"个评委打分");
            int score = sc.nextInt();
            //判断合法性
            if (score<0||score>100){
                System.out.println("输入分数有误!");
                i--;
            }else {
                arr[i]=score;
            }
        }
        return arr;
    }
}